package Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Test2 {

    public static class StudentComparator implements Comparator<Student>{

        @Override
        public int compare(Student o1, Student o2) {
            return o2.getAge() - o1.getAge();
        }
    }

    public static void main(String[] args) {
        Student s1 = new Student(12,180,"man");
        Student s2 = new Student(15,190,"women");
        Student s3 = new Student(18,170,"man");
        Student[] list = {s3,s1,s2};
        Arrays.sort(list);
        Arrays.sort(list, new StudentComparator());
        for (Student cur: list) {
            System.out.println(cur);
        }

        List<Student> ls = new ArrayList<Student>();
        ls.add(s2);ls.add(s3);ls.add(s1);
        ls.sort(new StudentComparator());
        for( Student cur : ls){
            System.out.println(cur);
        }

    }
}
